package com.hualan.service;

import com.hualan.domain.User;
import com.hualan.domain.UserAndRole;
import com.hualan.mapper.UserMapper;
import com.hualan.service.impl.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> findAllAdUser() {
        List<User> list = userMapper.findAllAdUser();
        return userMapper.findAllAdUser();
    }

    @Override
    public List<User> findAllNUser() {
        return userMapper.findAllNUser();
    }

    @Override
    public int findAdUserByUsername(String username, String password) {
        //登录业务
        User user = userMapper.findAdUserByUsername(username);

        //登录逻辑判断
        if (user==null){
            return 0;
        }else if (user.getPassword().equals(password)){
            //管理员登录
            if (user.getRole() == 1){
                return 11;
            }
            //咨询师登录
            if (user.getRole() == 2){
                return 21;
            }else {
                //用户登录
                return 30;
            }
        }else{
            return 2;
        }
    }

    @Override
    public List<UserAndRole> findAllNormalConsultantUser() {
        return userMapper.findAllNormalConsultantUser();
    }

    @Override
    public List<UserAndRole> findLikeNormalConsultantUser(String message) {
        return userMapper.findLikeNormalConsultantUser(message);
    }

    @Override
    public int insertUserNormalConsultant(User user) {
        return userMapper.insertSelective(user);
    }

    @Override
    public int updateUserNormalConsultant(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int deleteUserNormalConsultant(Long id) {
        return userMapper.deleteByPrimaryKey(id);
    }
}
